var do_App = sm("do_App");
var do_Page = sm("do_Page");
var nf = sm("do_Notification");
var helperOpen = require("helper/open");
var signCommunity=2;//未签到
//左上角-返回
var headerLeft = ui("headerLeft");
headerLeft.on("touch", function() {
	do_App.closePage({fromPage:"honorIndex",signCommunity:signCommunity});
});
//andriod返回键
do_Page.on("back", function() {
	do_App.closePage({fromPage:"honorIndex",signCommunity:signCommunity});
});
var headerRight=ui("headerRight");
headerRight.on("touch", function() {
	helperOpen.open("source://view/honor/rule/index.ui");
});
/** **************tab 切换**************** */
var viewShower = ui("viewShower");
var tabIndex2 = 0;
var aLayoutTab0 = ui("aLayoutTab0");
var aLayoutTab1 = ui("aLayoutTab1");
var tabAout = [ aLayoutTab0, aLayoutTab1];

var labelTab0 = ui("labelTab0");
var labelTab1 = ui("labelTab1");
var tabLabel = [ labelTab0, labelTab1];

var showIndex = 0
tabAout.forEach(function(foot, tabIndex) {
	foot.on("touch", function(data, e) {
		if (tabIndex2 !== tabIndex) {
			tabAout[tabIndex2].bgColor = "00000000";
			tabLabel[tabIndex2].fontColor = "000000FF";
			tabAout[tabIndex].bgColor = "313131FF";
			tabLabel[tabIndex].fontColor = "FFFFFFFF";
			showIndex = tabIndex;
			viewShower.showView("main" + tabIndex);
			fire2reflashData(tabIndex);
		}
		tabIndex2 = tabIndex;
	});
});
var mains = [ {
	"id" : "main0",
	"path" : "source://view/honor/index/signin.ui"
}, {
	"id" : "main1",
	"path" : "source://view/honor/index/task.ui"
}];
viewShower.addViews(mains);
var openShowIndex=0;
//页面装载完成后，开始初始化工作
do_Page.on("loaded", function() {
	var data=do_Page.getData();
	if(null!=data&&null!=data.openShowIndex){
		openShowIndex=data.openShowIndex;
	}
	tabIndex2=openShowIndex;
	if(openShowIndex==0){
		tabAout[1].bgColor = "00000000";
		tabLabel[1].fontColor = "000000FF";
		tabAout[0].bgColor = "313131FF";
		tabLabel[0].fontColor = "FFFFFFFF";
	}else{
		tabAout[0].bgColor = "00000000";
		tabLabel[0].fontColor = "000000FF";
		tabAout[1].bgColor = "313131FF";
		tabLabel[1].fontColor = "FFFFFFFF";
	}
	viewShower.showView("main" + openShowIndex);
	fire2reflashData(openShowIndex);
	
});
/**
 * 刷新对应页面的数据
 * @param type
 */
function fire2reflashData(index){
	if (index == 0) {// 签到
		do_Page.fire("community_sign_tab_touch", index);
	} else if (index == 1) {// 新手任务
		do_Page.fire("new_task_tab_touch", index);
	}
}
do_Page.on("community_sign_back", function(data) {
	signCommunity=data.signCommunity;
});